package cn.edu.tju.elm.repository;

import cn.edu.tju.elm.model.VirtualWalletTransaction;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface VirtualWalletTransactionRepository extends JpaRepository<VirtualWalletTransaction, Long> {

    List<VirtualWalletTransaction> findByWalletIdOrderByTransactionTimeDesc(Long walletId);

    /**
     * 根据用户钱包ID查找交易记录
     * @param fromWalletId 转出钱包ID
     * @param toWalletId 转入钱包ID
     * @return 交易记录列表
     */
    @Query("SELECT t FROM VirtualWalletTransaction t WHERE t.fromWalletId = :fromWalletId OR t.toWalletId = :toWalletId ORDER BY t.transactionTime DESC")
    List<VirtualWalletTransaction> findByWalletIdsOrderByTransactionTimeDesc(@Param("fromWalletId") Long fromWalletId, @Param("toWalletId") Long toWalletId);

    /**
     * 根据订单ID查找交易记录
     * @param orderId 订单ID
     * @return 交易记录列表
     */
    List<VirtualWalletTransaction> findByOrderIdOrderByTransactionTimeDesc(Long orderId);

    /**
     * 根据状态查找交易记录
     * @param status 交易状态
     * @return 交易记录列表
     */
    List<VirtualWalletTransaction> findByStatusOrderByTransactionTimeDesc(String status);
}
